#!/bin/sh

set -e

if [ $# -ne 2 ]; then
  echo "USAGE: $0 VERSION CODENAME" >&2
  exit 1
fi

VER=$1
FULLVER=$VER
CODENAME=$2

[ "$(echo "$FULLVER" | grep -o -F . | wc -c)" -lt 3 ] && FULLVER="$FULLVER.0"

# update the files
sed -e 's/^\(.. |(version)| replace:: \).*$/\1'"$VER"'/' -i doc/geany.txt
sed -e 's/^\([ 	]*version="\)[^"]*\("\)/\1'"$FULLVER"'.0\2/' -i geany.exe.manifest

sed -e '
s/^\(#define VER_FILEVERSION      *\)[^ ].*$/\1'"$(echo "$FULLVER" | tr . ,)"',0/
s/^\(#define VER_FILEVERSION_STR  *\)[^ ].*$/\1"'"$VER"'"/
' -i geany_private.rc

sed -e 's/^\(AC_INIT([^,]*, *\[\)[^]]*\(\],\)/\1'"$VER"'\2/' -i configure.ac
sed -e 's/^\(#define GEANY_CODENAME[	]*"\)[^"]*\("\)/\1'"$CODENAME"'\2/' -i src/geany.h

sed -e '
1i Geany '"$VER"' (unreleased)\n\n
' -i NEWS

# show commit message to use
cat <<EOF
Message for the commit, after you have checked the changes:
-----------------------------------------------------------

Post release version bump

Say hello to Geany $VER "$CODENAME"!
EOF
